/* $RCSFile: ADNDynRating.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice/PageModules/CrmRating/ADNDynRating.cs $
 * $log$
 * Revision 19 2010/08/09 09:43:51  christian.surieux
 *   Added Log to cs sources files
 * Revision 6 2010/08/06 19:56:24  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

using AddonNice.Helpers;
using AddonNice.Diagnostics;
using AddonNice.Configuration;

using CrmSdk;
using AddonNice.CRMWrapper;

namespace AddonNice.CRMWrapper.CrmRating
{
    public class InstallRating : InstallDynEntity
    {
        public override DynEntity NewEntity(string schemaName,CRMWrapperBase wrapper)
        {
            if (InstallTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine(string.Format(CultureInfo.InvariantCulture,"[V]InstallRating NewEntity CALLED schemaName: {0}.",schemaName), InstallTraceSwitch.Sw.Info);
            switch ( schemaName )
            {
                case CrmStr.rating:
                return new ADNDynRating(wrapper,string.Empty);
                case CrmStr.ratingdetail:
                return new ADNDynRatingDetail(wrapper,string.Empty);
                case CrmStr.ratinganswer:
                return new ADNDynRatingAnswer(wrapper,string.Empty);
                default:
                return null;
            }
        }

        public override bool InstallInCrmServer(int PortalID,bool isMainPortal,IDictionary stateSaver,CRMWrapperBase wrapper,DynEntity dynEnt,bool publishCustom,bool publishSiteMap,bool publishIsv)
        {
            if (InstallTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine("[V]InstallRating InstallInCrmServer CALLED.", InstallTraceSwitch.Sw.Info);
            return base.InstallInCrmServer(PortalID,isMainPortal,stateSaver,wrapper,dynEnt,publishCustom,publishSiteMap,publishIsv);
        }
    }


	public class ADNDynRating : DynEntity
	{
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.rating)
            {}

            public override Type DynType
            { get { return typeof(ADNDynRating); } }

            public override string DynTypename
            {   get{ return CrmStr.rating;}}

            public override DynEntity Build()
            {
                return new ADNDynRating();
            }
            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynRating(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynRating(w, PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynRating(w,PrimaryKeyValue);}
        }

        static ADNDynRating(){new Ftor();} 


		/// <summary>
		/// Reserved for template methods: do not use directly
		/// </summary>
        public ADNDynRating(): base()
		{}

        public ADNDynRating(CRMWrapperBase w, string PrimaryFiedlValue)
			: base(w,CrmStr.rating)
		{
			title = PrimaryFiedlValue;
		}

		public ADNDynRating(CRMWrapperBase w, Guid CrmId)
			: base(w,CrmStr.rating, CrmId)
		{}

		public ADNDynRating(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w,CrmStr.rating,e,null,null)
		{}

		public ADNDynRating(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
           : base(w,CrmStr.rating,e,prop,s)
		{}

        public ADNDynRating(ResetWrapperHandler fn, string PrimaryFiedlValue)
			: base(fn,CrmStr.rating)
		{
			title = PrimaryFiedlValue;
		}

		public ADNDynRating(ResetWrapperHandler fn, Guid CrmId)
			: base(fn,CrmStr.rating, CrmId)
		{}

		public ADNDynRating(ResetWrapperHandler fn,InternalDynamicEntity e)
			: base(fn,CrmStr.rating,e,null,null)
		{}

		public ADNDynRating(ResetWrapperHandler fn,InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
           : base(fn,CrmStr.rating,e,prop,s)
		{}

        [CrmDynAttribute(CrmStr.rating)]
        public Guid ratingid
		{
			get
			{
				return KeyPropertyValue(CrmStr.ratingid);
			}
			set
			{
				AddKeyProperty(CrmStr.ratingid, value);
			}
		}
        
        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.ratingid) || KeyPropertyValue(CrmStr.ratingid) != crmId )
                ratingid  =   crmId;
        }

        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return ratingid;
           }
           set
           {
               ratingid    =   value;
           }
        }

        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.adntitle;
            }
           set
           {
                   base.PrimaryFieldName = value;
           }
        }

        [CrmDynAttribute(CrmStr.rating)]
        public string description
        {
            get
            {
                return StringPropertyValue(CrmStr.adndescription);
            }
            set
            {
                AddStringProperty(CrmStr.adndescription,value);
            }
        }

        [CrmDynAttribute(CrmStr.rating)]
        public string title 
        {
            get 
            {
                return StringPropertyValue(CrmStr.adntitle);
            }
            set 
            {
                AddStringProperty(CrmStr.adntitle,value);
            }
        }

        [CrmDynAttribute(CrmStr.rating)]
        public string assocentity 
        {
            get 
            {
                return StringPropertyValue(CrmStr.assocentity);
            }
            set 
            {
                AddStringProperty(CrmStr.assocentity,value);
            }
        }

        [CrmDynAttribute(CrmStr.rating)]
        public int starnumber 
        {
            get 
            {
                return NumberPropertyValue(CrmStr.starnumber);
            }
            set 
            {
                AddNumberProperty(CrmStr.starnumber,value);
            }
        }

        [CrmDynAttribute(CrmStr.rating)]
        public int addonniceid 
        {
            get 
            {
                return NumberPropertyValue(CrmStr.addonniceid);
            }
            set 
            {
                AddNumberProperty(CrmStr.addonniceid,value);
            }
        }

        [CrmDynAttribute(CrmStr.rating)]
        public Guid campaignid 
        {
			get
			{
				return LookupPropertyValue(CrmStr.adncampaignid);
			}
			set
			{
				AddLookupProperty(CrmStr.adncampaignid,CrmStr.campaign, value);
			}
        }

        public string campaignName
        {
			get
			{
				return LookupPropertyName(CrmStr.adncampaignid);
			}
        }

        #region Builder

        const string RatingDisplayName          =   "Rating";
        const string RatingDisplayColName       =   "Ratings";
        const string RatingPrimaryDisplayName   =   "Title";

        public override bool HasBuilder
        {
            get{ return true;}
        }

        public override List<MetaDataBuilder> Builder
        {
            get
            {
                if (InstallTraceSwitch.Sw.TraceVerbose)
                    Trace.WriteLine("[V]ADNDynRating Builder GET BEG.", InstallTraceSwitch.Sw.Info);
                EntityBuilder eb                =   new EntityBuilder(CrmStr.rating);
                eb.Description                  =   "Addon Nice Rating Crm entity.";
                eb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_DISPLAYNAME",RatingDisplayName);
                eb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_DISPLAYCOLNAME",RatingDisplayColName);
                eb.PrimaryFieldName             =   CrmStr.adntitle;
                eb.PrimaryFieldDisplayName      =   LocalizeHelper.Localize("CRMRATING_TITLERATING",RatingPrimaryDisplayName);
                eb.MaxLength                    =   250;
                
                List<AttributeBuilder> attList  =   new List<AttributeBuilder>();
                
                StringAttributeBuilder sb       =   new StringAttributeBuilder(CrmStr.rating,CrmStr.assocentity);
                sb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_ENTITYNAME","Entity Name");
                sb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_ENTITYNAMES","Entity Names");
                sb.MaxLength                    =   100;
                attList.Add(sb);
                
                MemoAttributeBuilder mb         =   new MemoAttributeBuilder(CrmStr.rating,CrmStr.adndescription);
                mb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_DESCRIPTION","Description");
                mb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_DESCRIPTIONS","Descriptions");
                mb.MaxLength                    =   1000;
                attList.Add(mb);
                
                IntegerAttributeBuilder ib      =   new IntegerAttributeBuilder(CrmStr.rating,CrmStr.addonniceid);
                ib.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_ADDONNICEID","Addon Nice Id");
                ib.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_ADDONNICEIDS","Addon Nice Ids");
                attList.Add(ib);

                ib                              =   new IntegerAttributeBuilder(CrmStr.rating,CrmStr.starnumber);
                ib.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_STARNUMBER","Star number");
                ib.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_STARNUMBERS","Star numbers");
                attList.Add(ib);
                
                List<One2ManyRelationBuilder> relList  =   new List<One2ManyRelationBuilder>();
                
                // Campaign relation
                string relSchemaName            =   string.Format("{0}_{1}",CrmStr.campaign,CrmStr.rating);
                string lookupDisplayName        =   LocalizeHelper.Localize("CRMRATING_RATING_CAMPAIGN", "Campaign");
                One2ManyRelationBuilder CampRel =   new One2ManyRelationBuilder(relSchemaName,CrmStr.campaign,CrmStr.rating,-1,
                    CrmStr.campaignid,lookupDisplayName,string.Empty,eb.DisplayName);
                CampRel.MenuGroup                =    InternalAssociatedMenuGroup.Marketing;
                // There is only one Parental relation, so this one will be referential
                CampRel.CascadeReparent          =   CascadeInternalType.NoCascade;
                CampRel.CascadeAssign            =   CascadeInternalType.NoCascade;
                CampRel.CascadeDelete            =   CascadeInternalType.RemoveLink;
                CampRel.CascadeShare             =   CascadeInternalType.NoCascade;
                CampRel.CascadeUnshare           =   CascadeInternalType.NoCascade;
                relList.Add(CampRel);

                MetaDataBuilder metab           =   new MetaDataBuilder(eb, attList,relList);
                List<MetaDataBuilder> Lst       =   new List<MetaDataBuilder>();
                Lst.Add(metab);
                if (InstallTraceSwitch.Sw.TraceVerbose)
                    Trace.WriteLine("[V]ADNDynRating Builder GET END.", InstallTraceSwitch.Sw.Info);
                return Lst;
            }
        }
        #endregion Builder

        #region Form Customizer

        public override bool HasFormCustomizer
        {
            get{ return true;}
        }

        public override bool CustomizeForm(IDictionary stateSaver,bool publishCustom,bool publishSiteMap,bool publishIsv)
        {
            if (InstallTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine("[V]ADNDynRating CustomizeForm BEG.", InstallTraceSwitch.Sw.Info);

            CrmUtil4Form util           =   new CrmUtil4Form((CrmWrapper4)wrapper, CrmStr.rating);
            ImportExportXml imXml       =   util.Init();

            bool ret                    =   true;
            string DisplayName          =   LocalizeHelper.Localize("CRMRATING_STARNUMBER", "Star number");

            if ( !util.ExistAttributeInFirstTabAndSection(CrmStr.starnumber) )
            {
                util.AddAttributeInFirstTabAndSection(CrmStr.starnumber,DisplayName,AttributeInternalType.Integer,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_ENTITYNAME","Entity Name");
                util.AddAttributeInSameRow(CrmStr.assocentity,DisplayName,AttributeInternalType.String,1,1);
                    
                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DESCRIPTION","Description");
                util.AddAttributeInLastRows(CrmStr.adndescription,DisplayName,AttributeInternalType.Memo,2,10);
                
                ret                         =   util.Save(imXml,publishCustom);
            }

            if (InstallTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ADNDynRating CustomizeForm END ret : {0}.",ret), InstallTraceSwitch.Sw.Info);
            return ret;
        }

        #endregion Form Customizer
    }

	public class ADNDynRatingDetail : DynEntity
	{
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.ratingdetail)
            {}

            public override Type DynType
            { get { return typeof(ADNDynRatingDetail); } }

            public override string DynTypename
            {   get{ return CrmStr.ratingdetail;}}

            public override DynEntity Build()
            {
                return new ADNDynRatingDetail();
            }
            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynRatingDetail(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynRatingDetail(w, PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynRatingDetail(w,PrimaryKeyValue);}
        }

        static ADNDynRatingDetail(){new Ftor();} 

        /// <summary>
		/// Reserved for template methods: do not use directly
		/// </summary>
        public ADNDynRatingDetail(): base()
		{}

        public ADNDynRatingDetail(CRMWrapperBase w, string PrimaryFiedlValue)
			: base(w,CrmStr.ratingdetail)
		{
			title = PrimaryFiedlValue;
		}

		public ADNDynRatingDetail(CRMWrapperBase w, Guid CrmId)
			: base(w,CrmStr.ratingdetail, CrmId)
		{}

		public ADNDynRatingDetail(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w,CrmStr.ratingdetail,e,null,null)
		{}

		public ADNDynRatingDetail(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
           : base(w,CrmStr.ratingdetail,e,prop,s)
		{}

        public ADNDynRatingDetail(ResetWrapperHandler fn, string PrimaryFiedlValue)
			: base(fn,CrmStr.ratingdetail)
		{
			title = PrimaryFiedlValue;
		}

		public ADNDynRatingDetail(ResetWrapperHandler fn, Guid CrmId)
			: base(fn,CrmStr.ratingdetail, CrmId)
		{}

		public ADNDynRatingDetail(ResetWrapperHandler fn,InternalDynamicEntity e)
			: base(fn,CrmStr.ratingdetail,e,null,null)
		{}

		public ADNDynRatingDetail(ResetWrapperHandler fn,InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
           : base(fn,CrmStr.ratingdetail,e,prop,s)
		{}

        [CrmDynAttribute(CrmStr.ratingdetail)]
        public Guid ratingdetailid
		{
			get
			{
				return KeyPropertyValue(CrmStr.ratingdetailid);
			}
			set
			{
				AddKeyProperty(CrmStr.ratingdetailid, value);
			}
		}
        
        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.ratingdetailid) || KeyPropertyValue(CrmStr.ratingdetailid) != crmId )
                ratingdetailid  =   crmId;
        }

        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return ratingdetailid;
           }
           set
           {
               ratingdetailid    =   value;
           }
        }

        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.adntitle;
            }
           set
           {
                   base.PrimaryFieldName = value;
           }
        }

        [CrmDynAttribute(CrmStr.ratingdetail)]
        public string description
        {
            get
            {
                return StringPropertyValue(CrmStr.adndescription);
            }
            set
            {
                AddStringProperty(CrmStr.adndescription,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratingdetail)]
        public string title 
        {
            get 
            {
                return StringPropertyValue(CrmStr.adntitle);
            }
            set 
            {
                AddStringProperty(CrmStr.adntitle,value);
            }
        }
        
        [CrmDynAttribute(CrmStr.ratingdetail)]
        public int addonniceid 
        {
            get 
            {
                return NumberPropertyValue(CrmStr.addonniceid);
            }
            set 
            {
                AddNumberProperty(CrmStr.addonniceid,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratingdetail)]
        public Guid campaignid 
        {
			get
			{
				return LookupPropertyValue(CrmStr.adncampaignid);
			}
			set
			{
				AddLookupProperty(CrmStr.adncampaignid,CrmStr.campaign, value);
			}
        }

        public string campaignName
        {
			get
			{
				return LookupPropertyName(CrmStr.adncampaignid);
			}
        }


        #region customer

        [CrmDynAttribute(CrmStr.ratingdetail)]
        public Guid accountid 
        {
            get 
            {
                return LookupPropertyValue(CrmStr.adnaccountid);
            }
            set 
            {
                AddLookupProperty(CrmStr.adnaccountid,CrmStr.account,value);
            }
        }

        public string accountName
        {
            get 
            {
                return LookupPropertyName(CrmStr.adnaccountid);
            }
        }

        [CrmDynAttribute(CrmStr.ratingdetail)]
        public Guid contactid 
        {
            get 
            {
                return LookupPropertyValue(CrmStr.adncontactid);
            }
            set 
            {
                AddLookupProperty(CrmStr.adncontactid,CrmStr.contact,value);
            }
        }

        public string contactName
        {
            get 
            {
                return LookupPropertyName(CrmStr.adncontactid);
            }
        }

        [CrmDynAttribute(CrmStr.ratingdetail)]
        public Guid leadid 
        {
            get 
            {
                return LookupPropertyValue(CrmStr.adnleadid);
            }
            set 
            {
                AddLookupProperty(CrmStr.adnleadid,CrmStr.lead,value);
            }
        }

        public string leadName
        {
            get 
            {
                return LookupPropertyName(CrmStr.adnleadid);
            }
        }

        #endregion customer

        [CrmDynAttribute(CrmStr.ratingdetail)]
        public Guid productid 
        {
			get
			{
				return LookupPropertyValue(CrmStr.adnproductid);
			}
			set
			{
				AddLookupProperty(CrmStr.adnproductid,CrmStr.product, value);
			}
        }

        public string productName
        {
			get
			{
				return LookupPropertyName(CrmStr.adnproductid);
			}
        }

        [CrmDynAttribute(CrmStr.ratingdetail)]
        public Guid ratingid 
        {
			get
			{
				return LookupPropertyValue(CrmStr.ratingid);
			}
			set
			{
				AddLookupProperty(CrmStr.ratingid,CrmStr.rating, value);
			}
        }

        public string ratingName
        {
			get
			{
				return LookupPropertyName(CrmStr.ratingid);
			}
        }

        const string RatingDetailDisplayName        =   "Rating Detail";
        const string RatingDetailDisplayColName     =   "Rating Details";
        const string RatingDetailPrimaryDisplayName =   "Title";

        #region Depends of entities
        
        public override bool DependsFromOtherEntities
        {
            get{ return true;}
        }

        /// <summary>
        /// Ordered List of entities (schema names) from ,which this entity depends
        /// </summary>
        public override SortedList<int,string> DependsFrom
        {
            get
            { 
                SortedList<int,string> Lst  =   new SortedList<int,string>();
                Lst.Add(0,CrmStr.rating);
                return Lst;
            }
        }
        
        #endregion Depends of entities

        #region Builder

        public override bool HasBuilder
        {
            get{ return true;}
        }

        public override List<MetaDataBuilder> Builder
        {
            get
            {
                EntityBuilder eb                =   new EntityBuilder(CrmStr.ratingdetail);
                eb.Description                  =   "Addon Nice Rating Item Crm entity.";
                eb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_DETAILDISPLAYNAME",RatingDetailDisplayName);
                eb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_DEATILDISPLAYCOLNAME",RatingDetailDisplayColName);
                eb.PrimaryFieldName             =   CrmStr.adntitle;
                eb.PrimaryFieldDisplayName      =   LocalizeHelper.Localize("CRMRATING_TITLERATING",RatingDetailPrimaryDisplayName);
                eb.MaxLength                    =   100;
                
                List<AttributeBuilder> attList  =   new List<AttributeBuilder>();
                
                MemoAttributeBuilder mb         =   new MemoAttributeBuilder(CrmStr.ratingdetail,CrmStr.adndescription);
                mb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_DESCRIPTION","Description");
                mb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_DESCRIPTIONS","Descriptions");
                mb.MaxLength                    =   80000;
                attList.Add(mb);

                IntegerAttributeBuilder ib      =   new IntegerAttributeBuilder(CrmStr.ratingdetail,CrmStr.addonniceid);
                ib.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_ADDONNICEID","Addon Nice Id");
                ib.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_ADDONNICEIDS","Addon Nice Ids");
                attList.Add(ib);

                List<One2ManyRelationBuilder> relList  =   new List<One2ManyRelationBuilder>();
                
                // RatingDetail relation
                string relSchemaName            =   string.Format("{0}_{1}",CrmStr.rating,CrmStr.ratingdetail);
                string lookupDisplayName        =   LocalizeHelper.Localize("CRMRATING_DETAIL_RATING", "Rating");
                One2ManyRelationBuilder RatingRel=   new One2ManyRelationBuilder(relSchemaName,CrmStr.rating,CrmStr.ratingdetail,-1,
                    CrmStr.ratingid,lookupDisplayName,string.Empty,eb.DisplayName);
                RatingRel.MenuGroup              =    InternalAssociatedMenuGroup.Marketing;
                // Default values are for Parental, this is Ok
                relList.Add(RatingRel);
                
                // Product relation
                relSchemaName                   =   string.Format("{0}_{1}",CrmStr.product,CrmStr.ratingdetail);
                lookupDisplayName               =   LocalizeHelper.Localize("CRMRATING_DETAIL_PRODUCT", "Product");
                One2ManyRelationBuilder RatRel  =   new One2ManyRelationBuilder(relSchemaName,CrmStr.product,CrmStr.ratingdetail,-1,
                    CrmStr.productid,lookupDisplayName,string.Empty,eb.DisplayName);
                RatRel.MenuGroup                =    InternalAssociatedMenuGroup.Marketing;
                // There is only one Parental relation, so this one will be referential
                RatRel.CascadeReparent          =   CascadeInternalType.NoCascade;
                RatRel.CascadeAssign            =   CascadeInternalType.NoCascade;
                RatRel.CascadeDelete            =   CascadeInternalType.RemoveLink;
                RatRel.CascadeShare             =   CascadeInternalType.NoCascade;
                RatRel.CascadeUnshare           =   CascadeInternalType.NoCascade;
                relList.Add(RatRel);

                // Account relation
                relSchemaName                   =   string.Format("{0}_{1}",CrmStr.account,CrmStr.ratingdetail);
                lookupDisplayName               =   LocalizeHelper.Localize("CRMRATING_DETAIL_ACCOUNT", "Account");
                One2ManyRelationBuilder AccRel  =   new One2ManyRelationBuilder(relSchemaName,CrmStr.account,CrmStr.ratingdetail,-1,
                    CrmStr.accountid,lookupDisplayName,string.Empty,eb.DisplayName);
                AccRel.MenuGroup                =    InternalAssociatedMenuGroup.Marketing;
                // There is only one Parental relation, so this one will be referential
                AccRel.CascadeReparent          =   CascadeInternalType.NoCascade;
                AccRel.CascadeAssign            =   CascadeInternalType.NoCascade;
                AccRel.CascadeDelete            =   CascadeInternalType.RemoveLink;
                AccRel.CascadeShare             =   CascadeInternalType.NoCascade;
                AccRel.CascadeUnshare           =   CascadeInternalType.NoCascade;
                relList.Add(AccRel);

                // Contact relation
                relSchemaName                   =   string.Format("{0}_{1}",CrmStr.contact,CrmStr.ratingdetail);
                lookupDisplayName               =   LocalizeHelper.Localize("CRMRATING_DETAIL_CONTACT", "Contact");
                One2ManyRelationBuilder ConRel  =   new One2ManyRelationBuilder(relSchemaName,CrmStr.contact,CrmStr.ratingdetail,-1,
                    CrmStr.contactid,lookupDisplayName,string.Empty,eb.DisplayName);
                ConRel.MenuGroup                =    InternalAssociatedMenuGroup.Marketing;
                // There is only one Parental relation, so this one will be referential
                ConRel.CascadeReparent          =   CascadeInternalType.NoCascade;
                ConRel.CascadeAssign            =   CascadeInternalType.NoCascade;
                ConRel.CascadeDelete            =   CascadeInternalType.RemoveLink;
                ConRel.CascadeShare             =   CascadeInternalType.NoCascade;
                ConRel.CascadeUnshare           =   CascadeInternalType.NoCascade;
                relList.Add(ConRel);

                // Lead relation
                relSchemaName                   =   string.Format("{0}_{1}",CrmStr.lead,CrmStr.ratingdetail);
                lookupDisplayName               =   LocalizeHelper.Localize("CRMRATING_DETAIL_LEAD", "Lead");
                One2ManyRelationBuilder LeadRel =   new One2ManyRelationBuilder(relSchemaName,CrmStr.lead,CrmStr.ratingdetail,-1,
                    CrmStr.leadid,lookupDisplayName,string.Empty,eb.DisplayName);
                LeadRel.MenuGroup               =    InternalAssociatedMenuGroup.Marketing;
                // There is only one Parental relation, so this one will be referential
                LeadRel.CascadeReparent         =   CascadeInternalType.NoCascade;
                LeadRel.CascadeAssign           =   CascadeInternalType.NoCascade;
                LeadRel.CascadeDelete           =   CascadeInternalType.RemoveLink;
                LeadRel.CascadeShare            =   CascadeInternalType.NoCascade;
                LeadRel.CascadeUnshare          =   CascadeInternalType.NoCascade;
                relList.Add(LeadRel);

                // Campaign relation
                relSchemaName                   =   string.Format("{0}_{1}",CrmStr.campaign,CrmStr.ratingdetail);
                lookupDisplayName               =   LocalizeHelper.Localize("CRMRATING_DETAIL_CAMPAIGN", "Campaign");
                One2ManyRelationBuilder CampRel =   new One2ManyRelationBuilder(relSchemaName,CrmStr.campaign,CrmStr.ratingdetail,-1,
                    CrmStr.campaignid,lookupDisplayName,string.Empty,eb.DisplayName);
                CampRel.MenuGroup               =    InternalAssociatedMenuGroup.Marketing;
                // There is only one Parental relation, so this one will be referential
                CampRel.CascadeReparent         =   CascadeInternalType.NoCascade;
                CampRel.CascadeAssign           =   CascadeInternalType.NoCascade;
                CampRel.CascadeDelete           =   CascadeInternalType.RemoveLink;
                CampRel.CascadeShare            =   CascadeInternalType.NoCascade;
                CampRel.CascadeUnshare          =   CascadeInternalType.NoCascade;
                relList.Add(CampRel);

                MetaDataBuilder metab           =   new MetaDataBuilder(eb, attList,relList);
                List<MetaDataBuilder> Lst       =   new List<MetaDataBuilder>();
                Lst.Add(metab);
                return Lst;
            }
        }
        #endregion Builder

        #region Form Customizer

        public override bool HasFormCustomizer
        {
            get{ return true;}
        }

        public override bool CustomizeForm(IDictionary stateSaver,bool publishCustom,bool publishSiteMap,bool publishIsv)
        {
            if (InstallTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine("[V]ADNDynRatingDetail CustomizeForm BEG.", InstallTraceSwitch.Sw.Info);

            CrmUtil4Form util           =   new CrmUtil4Form((CrmWrapper4)wrapper, CrmStr.ratingdetail);
            ImportExportXml imXml       =   util.Init();
            bool ret                    =   true;
            DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DETAIL_RATING", "Rating");
            if ( !util.ExistAttributeInFirstTabAndSection(CrmStr.ratingid) )
            {
                util.AddAttributeInFirstTabAndSection(CrmStr.ratingid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DETAIL_CAMPAIGN", "Campaign");
                util.AddAttributeInSameRow(CrmStr.adncampaignid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DETAIL_LEAD", "Lead");
                util.AddAttributeInLastRows(CrmStr.adnleadid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DETAIL_PRODUCT", "Product");
                util.AddAttributeInSameRow(CrmStr.adnproductid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DETAIL_ACCOUNT", "Account");
                util.AddAttributeInLastRows(CrmStr.adnaccountid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DETAIL_CONTACT", "Contact");
                util.AddAttributeInSameRow(CrmStr.adncontactid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DESCRIPTION","Description");
                util.AddAttributeInLastRows(CrmStr.adndescription,DisplayName,AttributeInternalType.Memo,2,10);

                ret                         =   util.Save(imXml,publishCustom);
            }
            if (InstallTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ADNDynRatingDetail CustomizeForm END ret : {0}.",ret), InstallTraceSwitch.Sw.Info);
            return ret;
        }

        #endregion Form
    }

	public class ADNDynRatingAnswer : DynEntity
	{
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.ratinganswer)
            {}

            public override Type DynType
            { get { return typeof(ADNDynRatingAnswer); } }

            public override string DynTypename
            {   get{ return CrmStr.ratinganswer;}}

            public override DynEntity Build()
            {
                return new ADNDynRatingAnswer();
            }
            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynRatingAnswer(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynRatingAnswer(w, PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynRatingAnswer(w,PrimaryKeyValue);}
        }

        static ADNDynRatingAnswer(){new Ftor();} 

		/// <summary>
		/// Reserved for template methods: do not use directly
		/// </summary>
        public ADNDynRatingAnswer(): base()
		{}

        public ADNDynRatingAnswer(CRMWrapperBase w, string PrimaryFiedlValue)
			: base(w,CrmStr.ratinganswer)
		{
			name    =   PrimaryFiedlValue;
		}

		public ADNDynRatingAnswer(CRMWrapperBase w, Guid CrmId)
			: base(w,CrmStr.ratinganswer, CrmId)
		{}

		public ADNDynRatingAnswer(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w,CrmStr.ratinganswer,e,null,null)
		{}

		public ADNDynRatingAnswer(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
           : base(w,CrmStr.ratinganswer,e,prop,s)
		{}

        public ADNDynRatingAnswer(ResetWrapperHandler fn, string PrimaryFiedlValue)
			: base(fn,CrmStr.ratinganswer)
		{
			name    =   PrimaryFiedlValue;
		}

		public ADNDynRatingAnswer(ResetWrapperHandler fn, Guid CrmId)
			: base(fn,CrmStr.ratinganswer, CrmId)
		{}

		public ADNDynRatingAnswer(ResetWrapperHandler fn,InternalDynamicEntity e)
			: base(fn,CrmStr.ratinganswer,e,null,null)
		{}

		public ADNDynRatingAnswer(ResetWrapperHandler fn,InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
           : base(fn,CrmStr.ratinganswer,e,prop,s)
		{}

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public Guid ratinganswerid
		{
			get
			{
				return KeyPropertyValue(CrmStr.ratinganswerid);
			}
			set
			{
				AddKeyProperty(CrmStr.ratinganswerid, value);
			}
		}
        
        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.ratinganswerid) || KeyPropertyValue(CrmStr.ratinganswerid) != crmId )
                ratinganswerid  =   crmId;
        }

        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return ratinganswerid;
           }
           set
           {
               ratinganswerid    =   value;
           }
        }

        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.adnname;
            }
           set
           {
                   base.PrimaryFieldName = value;
           }
        }

        [CrmDynAttribute(CrmStr.ratingdetail)]
        public override string name 
        {
            get 
            {
                return StringPropertyValue(CrmStr.adnname);
            }
            set 
            {
                AddStringProperty(CrmStr.adnname,value);
            }
        }
        
        [CrmDynAttribute(CrmStr.ratinganswer)]
        public string comment
        {
            get
            {
                return StringPropertyValue(CrmStr.adncomment);
            }
            set
            {
                AddStringProperty(CrmStr.adncomment,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public string address
        {
            get
            {
                return StringPropertyValue(CrmStr.adnaddress);
            }
            set
            {
                AddStringProperty(CrmStr.adnaddress,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public string city
        {
            get
            {
                return StringPropertyValue(CrmStr.adncity);
            }
            set
            {
                AddStringProperty(CrmStr.adncity,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public string zip
        {
            get
            {
                return StringPropertyValue(CrmStr.adnzip);
            }
            set
            {
                AddStringProperty(CrmStr.adnzip,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public string country
        {
            get
            {
                return StringPropertyValue(CrmStr.adncountry);
            }
            set
            {
                AddStringProperty(CrmStr.adncountry,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public string email
        {
            get
            {
                return StringPropertyValue(CrmStr.adnemail);
            }
            set
            {
                AddStringProperty(CrmStr.adnemail,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public string phone
        {
            get
            {
                return StringPropertyValue(CrmStr.adnphone);
            }
            set
            {
                AddStringProperty(CrmStr.adnphone,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public int addonniceid 
        {
            get 
            {
                return NumberPropertyValue(CrmStr.addonniceid);
            }
            set 
            {
                AddNumberProperty(CrmStr.addonniceid,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public double ratingvalue
        {
            get 
            {
                return DoublePropertyValue(CrmStr.ratingvalue);
            }
            set 
            {
                AddFloatProperty(CrmStr.ratingvalue,value);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public Guid leadid 
        {
			get
			{
				return LookupPropertyValue(CrmStr.adnleadid);
			}
			set
			{
				AddLookupProperty(CrmStr.adnleadid,CrmStr.lead, value);
			}
        }

        public string leadName
        {
            get 
            {
                return LookupPropertyName(CrmStr.adnleadid);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public Guid accountid 
        {
            get 
            {
                return LookupPropertyValue(CrmStr.adnaccountid);
            }
            set 
            {
                AddLookupProperty(CrmStr.adnaccountid,CrmStr.account,value);
            }
        }

        public string accountName
        {
            get 
            {
                return LookupPropertyName(CrmStr.adnaccountid);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public Guid contactid 
        {
            get 
            {
                return LookupPropertyValue(CrmStr.adncontactid);
            }
            set 
            {
                AddLookupProperty(CrmStr.adncontactid,CrmStr.contact,value);
            }
        }

        public string contactName
        {
            get 
            {
                return LookupPropertyName(CrmStr.adncontactid);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public Guid ratingdetailid 
        {
			get
			{
				return LookupPropertyValue(CrmStr.ratingdetailid);
			}
			set
			{
				AddLookupProperty(CrmStr.ratingdetailid,CrmStr.ratingdetail, value);
			}
        }

        public string ratingdetailName
        {
            get 
            {
                return LookupPropertyName(CrmStr.ratingdetailid);
            }
        }

        [CrmDynAttribute(CrmStr.ratinganswer)]
        public Guid campaignid 
        {
			get
			{
				return LookupPropertyValue(CrmStr.adncampaignid);
			}
			set
			{
				AddLookupProperty(CrmStr.adncampaignid,CrmStr.campaign, value);
			}
        }

        public string campaignName
        {
			get
			{
				return LookupPropertyName(CrmStr.adncampaignid);
			}
        }

        const string AnswerDisplayName          =   "Rating answer";
        const string AnswerDisplayColName       =   "Rating answers";
        const string AnswerPrimaryDisplayName   =   "Name";

        #region Depends of entities
        
        public override bool DependsFromOtherEntities
        {
            get{ return true;}
        }

        /// <summary>
        /// Ordered List of entities (schema names) from ,which this entity depends
        /// </summary>
        public override SortedList<int,string> DependsFrom
        {
            get
            { 
                SortedList<int,string> Lst  =   new SortedList<int,string>();
                Lst.Add(0,CrmStr.rating);
                return Lst;
            }
        }
        
        #endregion Depends of entities

        #region Builder

        public override bool HasBuilder
        {
            get{ return true;}
        }

        public override List<MetaDataBuilder> Builder
        {
            get
            {
                EntityBuilder eb                =   new EntityBuilder(CrmStr.ratinganswer);
                eb.Description                  =   "Addon Nice Rating Answer Crm entity.";
                eb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_ANSWERDISPLAYNAME",AnswerDisplayName);
                eb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_ANSWERDISPLAYCOLNAME",AnswerDisplayColName);
                eb.PrimaryFieldName             =   CrmStr.adnname;
                eb.PrimaryFieldDisplayName      =   LocalizeHelper.Localize("CRMRATING_ANSWERPRIMARYDISPLAYNAME",AnswerPrimaryDisplayName);
                eb.MaxLength                    =   100;

                List<AttributeBuilder> attList  =   new List<AttributeBuilder>();

                FloatAttributeBuilder db        =   new FloatAttributeBuilder (CrmStr.ratinganswer,CrmStr.ratingvalue);
                db.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_RATINGVALUE","Rating value");
                db.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_RATINGVALUES","Rating values");
                attList.Add(db);

                
                StringAttributeBuilder sb       =   new StringAttributeBuilder(CrmStr.ratinganswer,CrmStr.adnaddress);
                sb.MaxLength                    =   250;
                sb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_ADDRESS","Address");
                sb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_ADDRESSES","Addresses");
                attList.Add(sb);

                sb                              =   new StringAttributeBuilder(CrmStr.ratinganswer,CrmStr.adncity);
                sb.MaxLength                    =   100;
                sb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_CITY","City");
                sb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_CITIES","Cities");
                attList.Add(sb);

                sb                              =   new StringAttributeBuilder(CrmStr.ratinganswer,CrmStr.adnzip);
                sb.MaxLength                    =   100;
                sb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_ZIP","Zip code");
                sb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_ZIPS","Zip codes");
                attList.Add(sb);

                sb                              =   new StringAttributeBuilder(CrmStr.ratinganswer,CrmStr.adncountry);
                sb.MaxLength                    =   100;
                sb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_COUNTRY","Country");
                sb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_COUNTRIES","Countries");
                attList.Add(sb);

                sb                              =   new StringAttributeBuilder(CrmStr.ratinganswer,CrmStr.adnemail);
                sb.MaxLength                    =   100;
                sb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_EMAIL","E-Mail");
                sb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_EMAILS","E-Mails");
                attList.Add(sb);

                sb                              =   new StringAttributeBuilder(CrmStr.ratinganswer,CrmStr.adnphone);
                sb.MaxLength                    =   100;
                sb.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_PHONE","Phone");
                sb.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_PHONES","Phones");
                attList.Add(sb);

                MemoAttributeBuilder ma         =   new MemoAttributeBuilder(CrmStr.ratinganswer,CrmStr.adncomment);
                ma.MaxLength                    =   1000;
                ma.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_COMMENT","Comment");
                ma.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_COMMENTS","Comments");
                attList.Add(ma);

                IntegerAttributeBuilder ib      =   new IntegerAttributeBuilder(CrmStr.ratinganswer,CrmStr.addonniceid);
                ib.DisplayName                  =   LocalizeHelper.Localize("CRMRATING_ADDONNICEID","Addon Nice Id");
                ib.DisplayCollectionName        =   LocalizeHelper.Localize("CRMRATING_ADDONNICEIDS","Addon Nice Ids");
                attList.Add(ib);

                
                List<One2ManyRelationBuilder> relList  =   new List<One2ManyRelationBuilder>();
                
                // RatingDetail relation
                string relSchemaName            =   string.Format("{0}_{1}",CrmStr.ratingdetail,CrmStr.ratinganswer);
                string lookupDisplayName        =   LocalizeHelper.Localize("CRMRATING_ANSWER_DETAIL", "Rating Detail");
                One2ManyRelationBuilder DetailRel=   new One2ManyRelationBuilder(relSchemaName,CrmStr.ratingdetail,CrmStr.ratinganswer,-1,
                    CrmStr.ratingdetailid,lookupDisplayName,string.Empty,eb.DisplayName);
                DetailRel.MenuGroup              =    InternalAssociatedMenuGroup.Marketing;
                // Default values are for Parental, this is Ok
                relList.Add(DetailRel);
                
                // Lead relation
                relSchemaName                   =   string.Format("{0}_{1}",CrmStr.lead,CrmStr.ratinganswer);
                lookupDisplayName               =   LocalizeHelper.Localize("CRMRATING_ANSWER_LEAD", "Lead");
                One2ManyRelationBuilder LeadRel =   new One2ManyRelationBuilder(relSchemaName,CrmStr.lead,CrmStr.ratinganswer,-1,
                    CrmStr.leadid,lookupDisplayName,string.Empty,eb.DisplayName);
                LeadRel.MenuGroup               =    InternalAssociatedMenuGroup.Marketing;
                // There is only one Parental relation, so this one will be referential
                LeadRel.CascadeReparent         =   CascadeInternalType.NoCascade;
                LeadRel.CascadeAssign           =   CascadeInternalType.NoCascade;
                LeadRel.CascadeDelete           =   CascadeInternalType.RemoveLink;
                LeadRel.CascadeShare            =   CascadeInternalType.NoCascade;
                LeadRel.CascadeUnshare          =   CascadeInternalType.NoCascade;
                relList.Add(LeadRel);

                // Account relation
                relSchemaName                   =   string.Format("{0}_{1}",CrmStr.account,CrmStr.ratinganswer);
                lookupDisplayName               =   LocalizeHelper.Localize("CRMRATING_DETAIL_ACCOUNT", "Account");
                One2ManyRelationBuilder AccRel  =   new One2ManyRelationBuilder(relSchemaName,CrmStr.account,CrmStr.ratinganswer,-1,
                    CrmStr.accountid,lookupDisplayName,string.Empty,eb.DisplayName);
                AccRel.MenuGroup                =    InternalAssociatedMenuGroup.Marketing;
                // There is only one Parental relation, so this one will be referential
                AccRel.CascadeReparent          =   CascadeInternalType.NoCascade;
                AccRel.CascadeAssign            =   CascadeInternalType.NoCascade;
                AccRel.CascadeDelete            =   CascadeInternalType.RemoveLink;
                AccRel.CascadeShare             =   CascadeInternalType.NoCascade;
                AccRel.CascadeUnshare           =   CascadeInternalType.NoCascade;
                relList.Add(AccRel);

                // Contact relation
                relSchemaName                   =   string.Format("{0}_{1}",CrmStr.contact,CrmStr.ratinganswer);
                lookupDisplayName               =   LocalizeHelper.Localize("CRMRATING_DETAIL_CONTACT", "Contact");
                One2ManyRelationBuilder ConRel  =   new One2ManyRelationBuilder(relSchemaName,CrmStr.contact,CrmStr.ratinganswer,-1,
                    CrmStr.contactid,lookupDisplayName,string.Empty,eb.DisplayName);
                ConRel.MenuGroup                =    InternalAssociatedMenuGroup.Marketing;
                // There is only one Parental relation, so this one will be referential
                ConRel.CascadeReparent          =   CascadeInternalType.NoCascade;
                ConRel.CascadeAssign            =   CascadeInternalType.NoCascade;
                ConRel.CascadeDelete            =   CascadeInternalType.RemoveLink;
                ConRel.CascadeShare             =   CascadeInternalType.NoCascade;
                ConRel.CascadeUnshare           =   CascadeInternalType.NoCascade;
                relList.Add(ConRel);

                // Campaign relation
                relSchemaName                   =   string.Format("{0}_{1}",CrmStr.campaign,CrmStr.ratinganswer);
                lookupDisplayName               =   LocalizeHelper.Localize("CRMRATING_RATING_CAMPAIGN", "Campaign");
                One2ManyRelationBuilder CampRel =   new One2ManyRelationBuilder(relSchemaName,CrmStr.campaign,CrmStr.ratinganswer,-1,
                    CrmStr.campaignid,lookupDisplayName,string.Empty,eb.DisplayName);
                CampRel.MenuGroup                =    InternalAssociatedMenuGroup.Marketing;
                // There is only one Parental relation, so this one will be referential
                CampRel.CascadeReparent          =   CascadeInternalType.NoCascade;
                CampRel.CascadeAssign            =   CascadeInternalType.NoCascade;
                CampRel.CascadeDelete            =   CascadeInternalType.RemoveLink;
                CampRel.CascadeShare             =   CascadeInternalType.NoCascade;
                CampRel.CascadeUnshare           =   CascadeInternalType.NoCascade;
                relList.Add(CampRel);

                MetaDataBuilder metab           =   new MetaDataBuilder(eb, attList,relList);
                List<MetaDataBuilder> Lst       =   new List<MetaDataBuilder>();
                Lst.Add(metab);
                return Lst;
            }
        }

        #endregion Builder
        
        #region Form Customizer

        public override bool HasFormCustomizer
        {
            get{ return true;}
        }

        public override bool CustomizeForm(IDictionary stateSaver,bool publishCustom,bool publishSiteMap,bool publishIsv)
        {
            if (InstallTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine("[V]ADNDynRatingAnswer CustomizeForm BEG.", InstallTraceSwitch.Sw.Info);

            CrmUtil4Form util           =   new CrmUtil4Form((CrmWrapper4)wrapper, CrmStr.ratinganswer);
            ImportExportXml imXml       =   util.Init();
            bool ret                    =   true;
            DisplayName                 =   LocalizeHelper.Localize("CRMRATING_RATINGVALUE","Rating value");
            if ( !util.ExistAttributeInFirstTabAndSection(CrmStr.ratingvalue) )
            {
                util.AddAttributeInFirstTabAndSection(CrmStr.ratingvalue,DisplayName,AttributeInternalType.Decimal,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_ANSWER_CAMPAIGN", "Campaign");
                util.AddAttributeInSameRow(CrmStr.adncampaignid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_LEAD", "Lead");
                util.AddAttributeInLastRows(CrmStr.adnleadid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DETAIL", "Rating detail");
                util.AddAttributeInSameRow(CrmStr.ratingdetailid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DETAIL_ACCOUNT", "Account");
                util.AddAttributeInLastRows(CrmStr.adnaccountid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_DETAIL_CONTACT", "Contact");
                util.AddAttributeInSameRow(CrmStr.adncontactid,DisplayName,AttributeInternalType.Lookup,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_ADDRESS","Address");
                util.AddAttributeInLastRows(CrmStr.adnaddress,DisplayName,AttributeInternalType.String,2,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_CITY","City");
                util.AddAttributeInLastRows(CrmStr.adncity,DisplayName,AttributeInternalType.String,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_ZIP","Zip code");
                util.AddAttributeInSameRow(CrmStr.adnzip,DisplayName,AttributeInternalType.String,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_COUNTRY","Country");
                util.AddAttributeInLastRows(CrmStr.adncountry,DisplayName,AttributeInternalType.String,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_EMAIL","E-Mail");
                util.AddAttributeInSameRow(CrmStr.adnemail,DisplayName,AttributeInternalType.String,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_PHONE","Phone");
                util.AddAttributeInLastRows(CrmStr.adnphone,DisplayName,AttributeInternalType.String,1,1);

                DisplayName                 =   LocalizeHelper.Localize("CRMRATING_COMMENT","Comment");
                util.AddAttributeInLastRows(CrmStr.adncomment,DisplayName,AttributeInternalType.Memo,2,8);

                ret                         =   util.Save(imXml,publishCustom);
            }
            if (InstallTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ADNDynRatingAnswer CustomizeForm END ret : {0}.",ret), InstallTraceSwitch.Sw.Info);
            return ret;
        }

        #endregion Form
    }
}
